package com.situ.service.impl;

import com.situ.dao.DepartmentDao;
import com.situ.dto.PageEntity;
import com.situ.entity.Department;
import com.situ.service.IDepartmentService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class DepartmentServiceImpl implements IDepartmentService {

    DepartmentDao dao = new DepartmentDao();

    @Override
    public List<Department> selectList(String name, PageEntity page) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        DepartmentDao deptDao = (DepartmentDao)ac.getBean("deptDao");
        return deptDao.selectList(name, page);
    }

    @Override
    public Integer countDept(String name) {
        return dao.count(name);
    }

    @Override
    public void update(Department dept) {
        dao.update(dept);
    }

    @Override
    public void add(Department dept) {
        dao.add(dept);
    }

    @Override
    public Department selectById(Integer id) {
        List<Department> list = dao.selectById(id);
        if (list != null && !list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public void delete(Integer id) {
        dao.delete(id);
    }

    @Override
    public List<Department> selectAll() {
        return dao.selectAll();
    }
}
